package xubo.wangcaifeng.love2

import com.alibaba.fastjson.JSONObject
import org.apache.commons.lang3.time.FastDateFormat

object ObjUtils {
  private val dateFormat: FastDateFormat = FastDateFormat.getInstance("yyyyMMddHHmmssSSS")
  def apply(obj: JSONObject):(String,List[Double],String) = {
    val success = obj.getString("bussinessRst").equals("0000")
    val money = obj.getDouble("chargefee")
    val requestId = obj.getString("requestId")
    val receiverTime = obj.getString("receiveNotifyTime")
    val pCode = obj.getString("provinceCode")
    (requestId,List[Double]
      (1,
        if(success) 1 else 0,
        if(success) money else 0,
        if(success) caculateTime(requestId,receiverTime) else 0
      ),pCode)

  }
  def caculateTime(start: String, end: String): Long ={
    dateFormat.parse(end).getTime - dateFormat.parse(start.substring(0,17)).getTime
  }

}
